const { userInfo } = require('../models/user')

module.exports = function getUserInfo(req, res, next) {
  const info = req.session.userInfo
  if (info) {
    userInfo(info.id)
      .then((results) => {
        req.user = results[0]
        next()
      })
      .catch((err) => {
        console.log(err)
        next()
      })
  } else {
    next()
  }
}
